<?
include("config.php");

$link = mysql_connect ('localhost', DB_USER_NAME, DB_PASSWORD) or die ("Cannot join database");
mysql_select_db (DB_NAME);


$requete = "SELECT * FROM stream INNER JOIN user ON stream.user=user.pseudo WHERE pseudo LIKE '%" . $_POST['search'] . "%' ORDER BY date DESC LIMIT 0, 10";
$result = mysql_query ($requete);

echo '<div class=stream>';
	while($row = mysql_fetch_array($result))
	{
		
		echo '<div class=msg msg-id="1" user-id="24744541">';

		// Inclusion de l'image
		echo '<div class=user-image>
     		 <img width="48" height="48" data-user-id="24744541" class="user-profile-link" src="avatar/' . $row['user'] . '.jpg">
 			</div>';

		echo '<div class="msg-content">';

		echo '<div class="msg-row">';
		echo '<a href="index.php?user=' . $row['user'] . '"> ' . $row['user'] . '</a>';
	 	echo '</div>';

		echo '<div class="msg-row">';
		echo $row['resume'];
	 	echo '</div>';

		echo '<div class="msg-row">';
		$message = preg_replace($img_pattern, $img_repl, $row['message']);
		$message1 = preg_replace($regex_youtube, $youtube_repl, $message);
		$message2 = preg_replace($regex_daily, $daily_repl, $message1);
		echo $message2;
	 	echo '</div>';

		echo '<div class="msg-row">';
		echo  'Added: ' . date('d/n/Y', $row['date']) . ' at ' . date('h:i:s', $row['date']); 
		if(isset($_SESSION['pseudo']))
		{
			if($_SESSION['pseudo'] == "admin")
			{
				echo " <a href=\"index.php?&action=" . $row['id_stream'] . "\">Delete this stream </a>";
			}
		} 
	 	echo '</div>';

		echo '</div>';// Fin du div msg-content

		echo '</div>'; // Fin du div msgs
		echo '<br>';
	}
	echo '</div>';


?>
